package main

import "fmt"

func main() {
	array := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
	//reverse(array[:])
	//left(array[:], 3)
	//left1(array[:], 3)
	//left2(array[:], 3)
	//right(array[:], 3)
	//right1(array[:], 3)
	right2(array[:], 3)
	fmt.Println(array)
	reverse(nil)
}

func reverse(s []int) {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}

func left(s []int, n int) {
	reverse(s[:n])
	reverse(s[n:])
	reverse(s[:])
}

func left1(s []int, n int) {
	right(s, len(s)-n)
}

func left2(s []int, n int) {
	l := len(s)
	reverse(s[:])
	reverse(s[l-n:])
	reverse(s[:l-n])
}

func right(s []int, n int) {
	reverse(s[:])
	reverse(s[:n])
	reverse(s[n:])
}

func right1(s []int, n int) {
	left(s, len(s)-n)
}

func right2(s []int, n int) {
	l := len(s)
	reverse(s[l-n:])
	reverse(s[:l-n])
	reverse(s[:])
}
